package com.ebaby.web.entry;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bban.bo.JingWeiDu;
import com.bban.db.dao.GPSDAO;
import com.bban.db.util.DBHelper;
import com.bban.dto.base.Msg;
import com.bban.dto.vo.GPSVO;

public class GetHistoryLocationInfo extends HttpServlet {
	public Connection conn = null;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public GetHistoryLocationInfo() {
		super();
	}

	public Connection getConnection() throws Exception {

		return DBHelper.getConnection();

		// Class.forName("com.mysql.jdbc.Driver").newInstance();
		// Connection conn = java.sql.DriverManager
		// .getConnection(
		// "jdbc:mysql://58.248.48.147/bban?useUnicode=true&characterEncoding=GBK",
		// "root", "root");
		// return conn;
	}

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		// bbanID='13500000000'&pwd='xxxxx'

		String bbanID = request.getParameter("bbanID");
		String pwd = request.getParameter("pwd");
		String from = request.getParameter("from");
		String to = request.getParameter("to");
		
		//request.getSession(true).getAttribute("now");
		

		try {
			String sql = "select * from gps where simid = '"
					+ bbanID
					+ "' and datetime BETWEEN '"
					+ from
					+ "' and '"
					+ to + "'";
			
//			System.out.println("sql="+sql);

			GPSDAO dao = new GPSDAO();
			Msg[] vos = dao.findVOs(sql);
			
			if(vos == null)
				return;
			
			PrintWriter pw = response.getWriter();
			String returnVal = "";
			if (vos != null) {
				for (int i = 0; i < vos.length; i++) {
					GPSVO vo = (GPSVO) vos[i];
					JingWeiDu jw = new JingWeiDu(vo.getJINGDU(), vo.getWEIDU());
					String jingDU = jw.getModifiedJingDuByDouble();
					String weiDu = jw.getModifiedWeiDuByDouble();
					String shiJian = vo.getDATETIME();
					returnVal = returnVal + jingDU + "," + weiDu + "," + shiJian + ";";
					pw.write(returnVal);
				}

			} else {
				pw.write("没有发现位置数据....");
			}
			pw.close();

		} catch (Exception ex) {
			ex.printStackTrace();

		}

	}

}
